
#include <stdio.h>
#include "httpresponse.h"



CHttpResponseMessage::CHttpResponseMessage()
{
	m_response = NULL;
	m_responseLen = 0;

	m_isMessageComplete = FALSE;
	m_parser.SetContent(m_response);

	memset(&m_httpResponsePtr, 0, sizeof(m_httpResponsePtr));

}

CHttpResponseMessage::~CHttpResponseMessage()
{
	if( NULL != m_response ) {
		free(m_response);
		m_response = NULL;
	}
}

BOOL CHttpResponseMessage::MakeResponseMessage( char *frag, int fragLen )
{
	char *temp = 0;

	if( !m_isMessageComplete ) {
		temp = (char *)realloc(m_response, (m_responseLen+fragLen)*sizeof(char));
		if( NULL == temp ) {
			fprintf(stderr, "CHttpResponseMessage::MakeResponseMessage, memory allocation failed!\n");
			free(m_response);
			m_response = NULL;
			return FALSE;
		}
		
		m_response = temp;
		memcpy((m_response+m_responseLen), frag, fragLen);

		m_responseLen += fragLen;

		return TRUE;
	} else {
		fprintf(stderr, "frag is NULL or ResponseMessage is completed,\n");
		return FALSE;
	}
}


BOOL CHttpResponseMessage::parseMessage()
{
	BOOL	isValidEnd = TRUE;

	return isValidEnd;
}
